import http from "./http";
import { objToParamStr } from "./utils";

/**
 * 查询文章分类
 * @param {Object} option
 * @param {Number} option.productId - 产品ID
 * @return {Promise} Array
 */
export async function queryArticleStock(option) {
  const url = "/client/queryArticleStock.htm";
  const params = {
    productId: "",
    ...option,
  };
  const res = await http.get(url, { params });
  return res.data;
}

/**
 * 查询文章列表
 * @param {Object} option
 * @param {Number} option.articleType - 文章类别ID
 * @param {Number} option.limit - 文章条数
 * @return {Promise} Array
 */
export async function queryArticleList(option) {
  const url = "/client/queryArticleList.htm";
  const params = {
    articleType: "",
    limit: 10,
    ...option,
  };
  const res = await http.get(url, { params });
  return res.data;
}

/**
 * 查询视频栏目
 * @param {Object} option
 * @param {Number} option.productId - 产品ID
 * @return {Promise} Array
 */
export async function queryVideoConfig(option) {
  const url = "/client/queryVideoConfig.htm";
  const params = {
    productId: "",
    ...option,
  };
  const res = await http.get(url, { params });
  return res.data;
}
/**
 * 查询视频列表
 * @param {Object} option
 * @param {Number} option.videoConfigId - 视频栏目id
 * @param {Number} option.productId - 产品id
 * @param {Number} option.clientCentralToken - token
 * @param {Number} option.pageSize - 文章条数
 * @param {Number} option.currentPage - 文章页码
 * @return {Promise} Array
 */
export async function queryRecordChargeLiveList(option) {
  const url = "/client/queryRecordChargeLiveList.htm";
  const params = {
    videoConfigId: "",
    productId: "",
    clientCentralToken: "",
    pageSize: 10,
    currentPage: 1,
    ...option,
  };
  const res = await http.get(url, { params });
  return res.data;
}
/**
 * 查询视频权重列表
 * @param {Object} option
 * @param {Number} option.videoConfigId - 视频栏目id
 * @param {Number} option.productId - 产品id
 * @param {Number} option.clientCentralToken - token
 * @param {Number} option.pageSize - 文章条数
 * @param {Number} option.currentPage - 文章页码
 * @return {Promise} Array
 */
export async function queryRecordChargeLiveListByWeight(option) {
  const url = "/client/queryRecordChargeLiveListByWeight.htm";
  const params = {
    videoConfigId: "",
    productId: "",
    clientCentralToken: "",
    pageSize: 10,
    currentPage: 1,
    ...option,
  };
  const res = await http.get(url, { params });
  return res.data;
}

// 课程表
export const getNoticeList = async (option) => {
  const url = "/client/live/table/list.htm";
  const params = {
    productId: "",
    beginTimeStr: "",
    endTimeStr: "",
    ...option,
  };
  return http.get(url, { params });
};
// 首页视频预告
export const getVideoPage = async (option) => {
  const url = "/client/viedo/page.htm";
  const params = {
    productId: "",
    ...option,
  };
  return http.get(url, { params });
};
/**
 * 查询轮播
 * @param {Object} option
 * @param {Number} option.productSource - 来源 0App 1客户端
 * @param {Number} option.bannerTypeId - 11首页轮播bannerID
 * @param {Number} option.checkCode - 产品校验码
 */
export const getNewClientBanner = async (option) => {
  const url = "/client/getNewClientBanner.htm";
  const params = {
    productSource: 1,
    bannerTypeId: 11,
    ...option,
  };
  return http.get(url, { params });
};

/**
 * 连线大咖列表
 * @param {Object} option
 * @param {Number} option.limit - 条数
 */
export const getConnectList = async (option) => {
  const url = "/client/connect/list.htm";
  const params = {
    // limit: "",
    ...option,
  };
  return http.get(url, { params });
};
/**
 * 股票搜索
 * @param {Object} params
 * @param {Number} params.path
 * @param {Number} params.pageSize - 请求条数
 * @param {String} params.name - 股票名称
 * @return {Promise} Array
 */
export async function getStockList(params) {
  const url = "http://app.yueniucj.com/app/clickSearchContent.htm";
  const send = {
    searchType: 1,
    limit: 6,
    ...params,
  };
  const res = await fetch(`${url}?${objToParamStr(send)}`);
  const { data } = await res.json();
  return data;
}
/**
 * 更新提问连线大咖股票次数
 * @param {Object} option
 * @param {Number} option.stockCode - 股票代码
 */
export const updateConnect = async (option) => {
  const url = "/client/connect/update.htm";
  const params = {
    stockCode: "",
    ...option,
  };
  return http.get(url, { params });
};

/**
 * 用户行为统计
 * @param {Object} option
 * @return {Promise} Array
 */
export async function userClickUpdate(option) {
  const url = "/client/insertUserBeInfoDate.htm";
  const data = JSON.stringify(option);
  const params = {
    data: data,
  };
  const res = await http.post(url, params);
  return res;
}
